home *** CD-ROM | disk | FTP | other *** search
- #
- # lgets.test
- #
- # Tests for the lgets command.
- #---------------------------------------------------------------------------
- # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: lgets.test,v 2.0 1992/10/16 04:49:57 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- Test lgets-1.1 {lgets command} {
- lgets
- } 1 {wrong # args: lgets fileId [varName]}
-
- Test lgets-1.2 {lgets command} {
- lgets a b c
- } 1 {wrong # args: lgets fileId [varName]}
-
- Test lgets-1.3 {lgets command} {
- lgets a
- } 1 {bad file identifier "a"}
-
- set f [open test2.tmp w]
- Test lgets-1.4 {lgets command} {
- lgets $f
- } 1 "\"$f\" wasn't opened for reading"
- catch {close $f}
-
- set f [open test2.tmp w]
- puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
- puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
- puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
- puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" nonewline
- puts $f "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
- close $f
-
- Test lgets-1.5 {lgets command with long line} {
- set f [open test2.tmp]
- set x [lgets $f]
- close $f
- set x
- } 0 {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
-
- Test lgets-1.6 {lgets command with long line} {
- set f [open test2.tmp]
- set x [lgets $f y]
- close $f
- list $x $y
- } 0 {260 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ}
-
- Test lgets-1.7 {lgets command and end of file} {
- set f [open test2.tmp w]
- puts $f "Test1\nTest2" nonewline
- close $f
- set f [open test2.tmp]
- set x {}
- set y {}
- lappend x [lgets $f y] $y
- set y {}
- lappend x [lgets $f y] $y
- set y {}
- lappend x [lgets $f y] $y
- close $f
- set x
- } 0 {5 Test1 5 Test2 -1 {}}
-
- Test lgets-2.1 {lgets command} {
- catch {unset data}
- set data(0) [list aaa b cccc]
- set data(1) [list aaaa \" ccc]
- set data(2) [list aaaaa \" cc]
- set data(3) [list aaaaa \"\" \} \{ \n c]
- set data(4) [list bcad \n defg \n nypq]
- set data(5) [list {BCAD {AAA
- BBB
- CCC}
- defg
- nypq}]
- set data(6) [list [replicate ABD 200] "\n" [replicate XYZ 100]]
- set data(7) [list [replicate ABD 255] "\n" [replicate XYZ 100]]
- set data(8) [list [replicate ABD 256] "\n" [replicate XYZ 100]]
- set data(9) [list [replicate "AAA\nBBB" 100]]
-
- set fh [open test1.tmp w]
- loop idx 0 10 {
- puts $fh $data($idx)
- }
- close $fh
- set fh [open test1.tmp]
- concat {}
- } 0 {}
-
- Test lgets-2.2 {lgets command} {
- lgets $fh
- } 0 $data(0)
-
- Test lgets-2.3 {lgets command} {
- lgets $fh retvar
- set retvar
- } 0 $data(1)
-
- Test lgets-2.4 {lgets command} {
- lgets $fh
- } 0 $data(2)
-
- Test lgets-2.5 {lgets command} {
- lgets $fh retvar
- set retvar
- } 0 $data(3)
-
- Test lgets-2.6 {lgets command} {
- lgets $fh
- } 0 $data(4)
-
- Test lgets-2.7 {lgets command} {
- lgets $fh retvar
- set retvar
- } 0 $data(5)
-
- Test lgets-2.8 {lgets command} {
- lgets $fh retvar
- set retvar
- } 0 $data(6)
-
- Test lgets-2.9 {lgets command} {
- lgets $fh retvar
- set retvar
- } 0 $data(7)
-
- Test lgets-2.10 {lgets command} {
- lgets $fh retvar
- set retvar
- } 0 $data(8)
-
- Test lgets-2.11 {lgets command} {
- lgets $fh retvar
- set retvar
- } 0 $data(9)
-
- catch {close $fh}
- unlink -nocomplain {test1.tmp test2.tmp}
-
-